package com.sjy.ylxt.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.sjy.ylxt.entity.basic.ResultBody;
import com.sjy.ylxt.entity.domain.YlxtAdmin;
import com.sjy.ylxt.entity.domain.YlxtEscorts;
import com.sjy.ylxt.entity.dto.AddAdminDTO;
import com.sjy.ylxt.entity.dto.AddEscortsDTO;
import com.sjy.ylxt.entity.dto.QueryEscortsDTO;
import com.sjy.ylxt.enums.DeleteFlagEnum;
import com.sjy.ylxt.factory.O2O;
import com.sjy.ylxt.service.YlxtEscortsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * @Author: lils
 * @CreateTime: 2024-12-12
 * @Description: 陪诊员控制层
 */

/**
 * 陪诊员管理
 */
@RestController
@RequestMapping("/escorts")
public class EscortsController {

    @Resource
    private YlxtEscortsService escortsService;
    /**
     * 添加陪诊员
     * @return
     */
    @PostMapping("/add")
    public ResultBody<?> addEscorts(
            @RequestParam @NotBlank(message = "陪诊员姓名不能为空") String userName,
            @RequestParam @NotBlank(message = "手机号不能为空") String phoneNumber,
            @RequestParam @NotBlank(message = "密码不能为空") String passWord,
            @RequestParam @NotBlank(message = "邮箱不能为空") String email,
            @RequestParam @NotBlank(message = "资格证书不能为空") String companionCertificate,
            @RequestParam @NotBlank(message = "工作经验不能为空") String companionExperience,
            @RequestParam  Long fileId
    ) {
        AddEscortsDTO addEscortsDTO = new AddEscortsDTO();
        addEscortsDTO.setUserName(userName);
        addEscortsDTO.setPhoneNumber(phoneNumber);
        addEscortsDTO.setPassWord(passWord);
        addEscortsDTO.setEmail(email);
        addEscortsDTO.setCompanionCertificate(companionCertificate);
        addEscortsDTO.setCompanionExperience(companionExperience);
        addEscortsDTO.setFileId(fileId);
        return escortsService.addEscorts(addEscortsDTO);
    }

    /**
     * 编辑陪诊员
     */
    @PostMapping("/edit")
    public ResultBody<?> editEscorts(
            @RequestParam @NotBlank(message = "陪诊员姓名不能为空") String userName,
            @RequestParam @NotBlank(message = "手机号不能为空") String phoneNumber,
            @RequestParam @NotBlank(message = "密码不能为空") String passWord,
            @RequestParam @NotBlank(message = "邮箱不能为空") String email,
            @RequestParam @NotBlank(message = "资格证书不能为空") String companionCertificate,
            @RequestParam @NotBlank(message = "工作经验不能为空") String companionExperience,
            @RequestParam @NotBlank(message = "id不能为空") String id) {
        AddEscortsDTO addEscortsDTO = new AddEscortsDTO();
        addEscortsDTO.setUserName(userName);
        addEscortsDTO.setPhoneNumber(phoneNumber);
        addEscortsDTO.setPassWord(passWord);
        addEscortsDTO.setEmail(email);
        addEscortsDTO.setCompanionCertificate(companionCertificate);
        addEscortsDTO.setCompanionExperience(companionExperience);
        YlxtEscorts ylxtEscorts = O2O.escortsToDomain(addEscortsDTO);
        //todo 待补充 获取创建用户信息
        ylxtEscorts.setDeleteFlag(DeleteFlagEnum.UN_DELETE_FLAG.getCode());
        ylxtEscorts.setCreateUser("admin");
        ylxtEscorts.setUpdateUser("admin");
        ylxtEscorts.setCreateTime(new Date());
        ylxtEscorts.setUpdateTime(new Date());

        ylxtEscorts.setId(Integer.valueOf(id));
        escortsService.updateById(ylxtEscorts);
        return ResultBody.success();
    }

    /**
     * 陪诊员分页查询
     * @param pageNum
     * @param pageSize
     * @param userName
     * @param phoneNumber
     * @param email
     * @return
     */
    @PostMapping("/page-list")
    public ResultBody<?> queryEscorts(
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String userName,
            @RequestParam(required = false) String phoneNumber,
            @RequestParam(required = false) String email) {
        QueryEscortsDTO dto = new QueryEscortsDTO();
        dto.setPageNum(pageNum);
        dto.setPageSize(pageSize);
        dto.setUserName(userName);
        dto.setPhoneNumber(phoneNumber);
        dto.setEmail(email);

        return escortsService.pageList(dto);
    }
    /**
     * 禁用陪诊员
     */
    @PostMapping("/disable")
    public ResultBody<?> disableEscorts(@RequestParam("id") String id) {
        return escortsService.disable(id);
    }

    /**
     * 启用陪诊员
     */
    @PostMapping("/enable")
    public ResultBody<?> enableEscorts(@RequestParam("id") String id) {
        return escortsService.enable(id);
    }

    /**
     * 查看陪诊员详情
     */
    @PostMapping("/detail")
    public ResultBody<?> detail(@RequestParam("id") String id) {
        return escortsService.detail(id);
    }
}
